import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@Components/layout.vue'

const routes = [
    {
        path: '/',
        redirect: '/login',
        meta: { title: '登录页' },
    },
    {
        name: 'login',
        path: '/login',
        component: () => import('@Pages/login/index.vue'),
        meta: { title: '登录页' },
    },
    {
        path: '/',
        component: Layout,
        meta: { title: '首页', iconName: 'home' },
        children: [
            {
            name: 'home',
            path: 'home',
            component: () => import('@Pages/home/index.vue'),
            meta: { title: '首页' },
            },
        ],
    },
    {
        path: '/',
        component: Layout,
        meta: { title: '系统设置', iconName: 'setting' },
        children: [
            {
                name: 'rule-setting',
                path: '/system-setting/rule-setting',
                component: () => import('@Pages/system-setting/rule-setting/index.vue'),
                meta: { title: '规则设置', keepAlive: true },
            },
            {
                name: 'app-permission-setting',
                path: '/system-setting/permission-setting/app-permission-setting',
                component: () => import('@Pages/system-setting/permission-setting/app-permission-setting/index.vue'),
                meta: { title: '应用权限', keepAlive: true },
            },
            {
                name: 'business-permission-setting',
                path: '/system-setting/permission-setting/business-permission-setting',
                component: () => import('@Pages/system-setting/permission-setting/business-permission-setting/index.vue'),
                meta: { title: '业务权限', keepAlive: true },
            },
        ],
    },
    {
        path: '/:pathMatch(.*)*',
        component: Layout,
        redirect: '404',
        children: [
            {
                name: '404',
                path: '404',
                component: () => import('@Pages/404/index.vue'),
                meta: { title: '404' },
            },
        ],
    },
]

const routerHistory = createWebHistory()
const router = createRouter({
    history: routerHistory,
    routes,
})

router.beforeEach((to, from, next) => {
    next()
    document.getElementById('appLoading').remove()
})

export default router
